<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>菜单添加 - 我的后台管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="__CSS__/iconfont.css">
	<link rel="stylesheet" href="__CSS__/common.css">	
</head>
<body class="childrenBody">
	
	<div class="breadcrum">
		<div class="navgat">
			<h3>
				<a href="javascript:;" class=""><i class="iconfont">&#xe641;</i></a>
				<span>&gt;</span>
				<a href="javascript:;" class="">菜单管理</a>
				<span>&gt;</span>
				<a href="javascript:;" class="">添加</a>
			</h3>
		</div>
		<div class="refresh">
			<div class="layui-btn-group">
				<a onclick="location.reload();" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe669;</i></a>
				<a onclick="history.back();" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe65c;</i></a>
			</div>
		</div>
	</div>
	<div class="main">
		<form class="layui-form" style="width:80%;" id="form_data">
			<div class="layui-form-item">
				<label class="layui-form-label">菜单名称</label>
				<div class="layui-input-block">
					<input type="text" name="name" class="layui-input linksName" lay-verify="required" placeholder="请输入菜单名称">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">跳转方法</label>
				<div class="layui-input-block">
					<input type="text" name="link" class="layui-input linksUrl" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">上级菜单</label>
				<div class="layui-input-inline">
					<select name="pid" lay-verify="required">
						{volist name="parents" id="vo"}
							<option value="{$vo.nav_id}">{$vo.name}</option>
						{/volist}
					</select>
				</div>		
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">功能描述</label>
				<div class="layui-input-block">
					<textarea name="desc" placeholder="请输入功能描述" class="layui-textarea linksDesc"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">序号</label>
				<div class="layui-input-block">
					<input type="text" name="ordernum" class="layui-input masterEmail" lay-verify="number" >
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">显示图标</label>
				<div class="layui-input-block">
					<input type="text" name="icon" class="layui-input masterEmail" lay-verify="email" placeholder="请输入icon">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">权限设置</label>
				<div class="layui-input-block">
					<input type="checkbox" name="show" value="1" title="是否显示">
					<input type="checkbox" name="inright" value="1" title="加入权限">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn" id="btn_sub" lay-filter="addmenu">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
			</div>
		</form>
	</div>

	<script type="text/javascript" src="__STATIC__/layui/layui.js"></script>
	<script type="text/javascript">
		
		layui.use(['form','layer'],function(){
			var form  = layui.form,
				layer = layui.layer,
				$ = layui.$;

			// 选择菜单
			form.on("select(level)",function(data){
				var level = data.value;
				$.ajax({
					type: "POST",
			        url:"{:url('admin/menu/ajax_get_parent_menu')}",
					data:{"level":level},
			        success: function(data){
			        	var str = "";
			        	if (data.length > 0) {
				        	for (var i = 0; i < data.length; i++) {
								str += '<option value="'+data[i]['nav_id']+'">'+data[i]['name']+'</option>';
				        	}

				        	$("#parents_m").html(str);
			        	}else{

				        	$("#parents_m").html('');
			        	}
			        		// 更新渲染
							form.render('select');
			        }
				})
			})

		 	// 提交数据
			$("#btn_sub").click(function(){
		 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.2});
		        // 序列化表单数据
				var form_data = $("#form_data").serialize();
				$.ajax({
					type: "POST",
			        url:"/admin/menu/edit?flag=add",
					data:form_data,
					dataType:'json',
			        success: function(data){
		            	top.layer.close(index);
			        	
			        	if(data.status == -1){
			        		layer.alert(data.msg, {icon: 2});
			        	}else{
			        		layer.msg(data.msg, {icon: 1});
			        	}
			        }
				})
			})
		})	
	</script>
</body>
</html>